/**
 * 
 */
package com.ssm.controller.admin;


import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssm.controller.SSMController;
import com.ssm.exception.ExceptionCode;
import com.ssm.exception.SsmException;
import com.ssm.model.bean.SsmResourceType;
import com.ssm.model.bean.SsmResources;
import com.ssm.model.mapper.ActionMapper;
import com.ssm.model.mapper.MenuMapper;
import com.ssm.model.mapper.ResourceTypeMapper;
import com.ssm.model.mapper.ResourcesMapper;
import com.ssm.util.SSMUtil;

/**
 * 
 * @author 危文涛<245108903@qq.com>
 * @version 2016年2月13日 下午3:53:04
 *
 */
@Controller
@RequestMapping(value="fileType")
public class FileTypeController extends AdminBaseController<SsmResourceType> {

	@RequestMapping(value="index")
	public String index(HttpServletRequest request)
	{
		List2Table(ResourceTypeMapper.class,null, request,false);
		request.setAttribute("WEB_TITLE", "文件类型列表");
		return "filetype/index";
	}
	@RequestMapping(value="edit")
	public String FileTypeEdit(HttpServletRequest request,SsmResourceType resourceType)
	{
		ResourceTypeMapper resourceTypeMapper=M.getMapper(ResourceTypeMapper.class);
		if(request.getMethod()=="POST")//添加&编辑资源类型
		{
			if(resourceType.getId()==null)//添加
			{
				resourceType.setCreatetime(nowTime().toString());
				if(resourceTypeMapper.insertSelective(resourceType)>0);
				else
					throw new SsmException(ExceptionCode.PARAM_NOT_FIND);
			}
			else//编辑
			{
				if(resourceTypeMapper.updateByPrimaryKeySelective(resourceType)>0);
				else
					throw new SsmException(ExceptionCode.PARAM_NOT_FIND);
			}
			return "redirect:index";
		}
		else//查看&显示资源类型界面
		{
			Integer id=null;
			if(request.getParameter("id")!=null)
				id=Integer.parseInt(request.getParameter("id"));
			if(id==null)//显示界面
			{
				request.setAttribute("WEB_TITLE", "添加文件类型");
			}
			else//查看
			{
			     resourceType=resourceTypeMapper.selectByPrimaryKey(id);
				if(resourceType==null)
					throw new SsmException(ExceptionCode.PARAM_NOT_FIND);
				request.setAttribute("item",resourceType);
				request.setAttribute("WEB_TITLE", "修改文件类型");
			}
			request.setAttribute("typelist",resourceTypeMapper.selectAll());
			return "filetype/edit";
		}
	}
	
	
	@RequestMapping(value="changeStatus")
	public String changeStatus(HttpServletRequest request)
	{
		 changeStatus(ResourceTypeMapper.class,request);
		 return "redirect:index";
	}
	
	
	
}
